package sprs;

import java.util.Arrays;

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation;

import scala.Tuple2;

public class Util {
	
	public static Tuple2<Double, double[]> coff(double[] x) {

		double[] ones = new double[x.length];
		PearsonsCorrelation pc = new PearsonsCorrelation();
		double max = -2;
		// double max0 = -2;
		double[] onePattern = null;
		;
		double[] zeroPatten = null;
		;
		for (int i = 1; i < ones.length; i++) {
			for (int j = 0; j < i; j++) {
				ones[j] = 1;
			}

			double temp = pc.correlation(x, ones);
			if (temp > max) {
				max = temp;
				onePattern = Arrays.copyOfRange(ones, 0, ones.length);
			}
			/*
			 * System.out.println("temp=" + temp); System.out.println("max1=" +
			 * max); System.out.println(Arrays.toString(ones));
			 * System.out.println(Arrays.toString(x));
			 */

		}
		for (int i = 1; i < ones.length; i++) {
			for (int j = 0; j < i; j++) {
				ones[j] = 0;
			}
			for (int j = i; j < ones.length; j++) {
				ones[j] = 1;
			}

			double temp = pc.correlation(x, ones);
			if (temp > max) {
				max = temp;
				onePattern = Arrays.copyOfRange(ones, 0, ones.length);
			}
			/*
			 * System.out.println("temp=" + temp); System.out.println("max=" +
			 * max); System.out.println(Arrays.toString(ones));
			 * System.out.println(Arrays.toString(x));
			 */

		}

		return new Tuple2<Double, double[]>(max, onePattern);
	}

}
